﻿/* ------------------------------------------------------------------------
* 【本类功能概述】
* 
* 创建人：
* 创建时间：2014/6/27 16:24:27
* 创建说明：
*
* 修改人： 
* 修改时间： 
* 修改说明：
* ------------------------------------------------------------------------
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace MS.Utility.Common
{
    public class UserHelper
    {
        /// <summary>
        /// 获取页面请求地址
        /// </summary>
        /// <returns></returns>
        public static string GetRequestUrl()
        {
            if (HttpContext.Current != null && HttpContext.Current.Request != null)
            {
                return HttpContext.Current.Request.RawUrl;
            }
            else
            {
                return "";
            }
        }

        /// <summary>
        /// 获取页面请求绝对地址
        /// </summary>
        /// <returns></returns>
        public static string GetRequestUrlAbsolutePath()
        {
            if (HttpContext.Current != null && HttpContext.Current.Request != null)
            {
                return HttpContext.Current.Request.Url.AbsolutePath;
            }
            else
            {
                return "";
            }
        }

        /// <summary>
        /// 获取页面请求来路地址
        /// </summary>
        /// <returns></returns>
        public static string GetRequestUrlReferrerAbsoluteUri()
        {
            if (HttpContext.Current != null && HttpContext.Current.Request != null && HttpContext.Current.Request.UrlReferrer != null)
            {
                return HttpContext.Current.Request.UrlReferrer.AbsoluteUri.ToString();
            }
            else
            {
                return "";
            }
        }

        /// <summary>
        /// 获取当前服务器名称
        /// </summary>
        /// <returns></returns>
        public static string GetServerName()
        {
            if (HttpContext.Current != null)
            {
                return HttpContext.Current.Server.MachineName;
            }
            else
            {
                return "127.0.0.1";
            }
        }

        /// <summary>
        /// 获取用户IP地址
        /// </summary>
        /// <returns>用户IP地址</returns>
        public static string GetUserIp()
        {
            if (HttpContext.Current != null && HttpContext.Current.Request != null)
            {
                return HttpContext.Current.Request.UserHostAddress;
            }
            else
            {
                return "127.0.0.1";
            }
        }

        public static int GetOrganizationID()
        {
            try
            {
                return 0;
            }
            catch
            {
                return 0;
            }
        }
    }
}
